package com.authine.cloudpivot.ext.applicationservice;

import cn.hutool.core.bean.BeanUtil;
import com.alibaba.cola.exception.BizException;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.authine.cloudpivot.ext.constants.AppConst;
import com.authine.cloudpivot.ext.constants.ModelConst;
import com.authine.cloudpivot.ext.constants.ServiceUrlConst;
import com.authine.cloudpivot.ext.dto.*;
import com.authine.cloudpivot.ext.dto.VendorScoreStatistics.VendorScoreQuotationDto;
import com.authine.cloudpivot.ext.dto.vendorStastics.*;
import com.authine.cloudpivot.ext.enums.FileExportEnum;
import com.authine.cloudpivot.ext.model.ReportRecord;
import com.authine.cloudpivot.ext.utils.*;
import com.authine.hermes.app.launcher.response.MultiResponse;
import com.authine.hermes.app.launcher.response.SingleResponse;
import com.authine.hermes.app.launcher.service.ApplicationService;
import com.authine.hermes.app.launcher.service.ApplicationServiceFoundation;
import com.authine.mvp.app.launcher.domain.SelectorFormat;
import com.authine.mvp.app.launcher.domain.utills.ApplicationContextUtils;
import com.authine.mvp.app.launcher.dto.bo.query.ListBOQuery;
import com.authine.mvp.app.launcher.dto.bo.query.expression.*;
import com.authine.mvp.app.launcher.dto.bo.response.BOList;
import com.google.common.collect.Maps;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.http.HttpMethod;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

import static com.authine.cloudpivot.ext.conf.ApplicationConf.EXPORT_REPORT_URL;
import static com.authine.cloudpivot.ext.conf.ApplicationConf.systemManagement;
import static com.authine.hermes.app.launcher.service.ApplicationServiceFoundation.CUSTOM_SERVICE;

@Slf4j
@Path("VendorService")
public class VendorService extends ApplicationService {
    private static  final String REPORTSATISFYSCORE = "reportSatisfyScore";
    private static  final String BJSX = "bjsx";
    private NamedParameterJdbcTemplate jdbcTemplate = ApplicationContextUtils.getBean(NamedParameterJdbcTemplate.class);


    /**
     * 报价时效计算
     * @param item
     */
    private void quotationHourlyScore(Map<String, Object> item, VendorScoreQuotationDto item2) {
        Double v = item2.getBjsx().doubleValue();
        if (v != null && v != 0L){
            if (v <= 12 && v > 0) {
                item.put(BJSX,20L);
            } else if (v <= 24 && v > 12) {
                item.put(BJSX,15L);
            } else if (v <= 36 && v > 24) {
                item.put(BJSX,10L);
            } else if (v <= 48 && v > 36) {
                item.put(BJSX,5L);
            } else {
                item.put(BJSX,0L);
            }
        }
    }

    private void buildQuotationGoodVendorScore(List<VendorScoreQuotationDto> vendorScoreDtos, List<Map<String, Object>> vendors) {
        if (vendors != null && vendors.size() >0){
            vendors.forEach(item->{
                String name = (String) item.get("name");
                vendorScoreDtos.forEach(item2->{
                    String vendor_organization_name = item2.getVendor_organization_name();
                    if (StringUtils.equals(name,vendor_organization_name)){
                        calculateQuotationTime(item, item2);
                        quotationHourlyScore(item,item2);
                    }

                });


            });

        }
    }

    private void calculateQuotationTime(Map<String, Object> item, VendorScoreQuotationDto item2) {
        BigDecimal bjcs = item2.getBjcs();
        BigDecimal cycs = item2.getCycs();
        if (cycs != null && cycs.compareTo(BigDecimal.ZERO) != 0){
            Double v = bjcs.divide(cycs, 3, BigDecimal.ROUND_HALF_UP).doubleValue();
            if (v >= 0.75  && v.intValue() <= 1.0) {
                item.put(REPORTSATISFYSCORE,10L);
            } else if (v >= 0.65 && v < 0.75) {
                item.put(REPORTSATISFYSCORE,8L);
            } else if (v >= 0.55 && v < 0.65) {
                item.put(REPORTSATISFYSCORE,6L);
            } else if (v >= 0.45 && v < 0.55) {
                item.put(REPORTSATISFYSCORE,4L);
            } else if (v >= 0.30 && v < 0.45) {
                item.put(REPORTSATISFYSCORE,2L);
            } else {
                item.put(REPORTSATISFYSCORE,0L);
            }

        }else{
            item.put(REPORTSATISFYSCORE,0L);
        }
    }


    @Path("list_schemaCode_by_page")
    @POST
    @Operation(summary = "查询分页", tags = ApplicationServiceFoundation.CUSTOM_SERVICE)
    public com.alibaba.cola.dto.SingleResponse<BOList> list_schemaCode_by_page(@Parameter ListBOQuery baseQueryDto) {
        com.alibaba.cola.dto.SingleResponse<BOList> boListSingleResponse = listBO(baseQueryDto);
        return boListSingleResponse;
    }




    @Path("vendorGoodList")
    @POST
    @Operation(summary = "供应书商品目录",tags = CUSTOM_SERVICE)
    public com.alibaba.cola.dto.SingleResponse<BOList> vendorGoodList(@Parameter VendorGoodDto good){
        PageObject<Map<String, Object>> pageObject = new PageObject<Map<String, Object>>();
        List<Map<String, Object>> orderList = null;
        Integer count = 0;
        try {
            Integer pageCurrent = good.getPageCurrent() == null ? 1 : good.getPageCurrent();
            Integer pageSize = good.getPageSize() == null ? 10 : good.getPageSize();
            // 设置当前页
            good.setPageCurrent(pageCurrent);
            // 设置每页显示的条数
            pageObject.setPageSize(pageSize);
            // 设置总记录数

            count = VendorGoodJdbcUtil.getCountSql(good);
            log.info("总条数:{}" + count);
            pageObject.setRowCount(count);
            pageObject.setPageCount(0);
            if (count != 0) {
                // 设置总页数
                int pageNum = count % pageSize == 0 ? count / pageSize : (count / pageSize) + 1;
                pageObject.setPageCount(pageNum);
                // 设置每页显示数据集合
                // 开始的记录数
                int start = (pageCurrent - 1) * pageSize;
                System.out.println(start + "-" + pageSize);
                orderList = VendorGoodJdbcUtil.getVendorGoodList(good, start, pageSize);
                pageObject.setData(orderList);
            } else {
                pageObject.setPageCount(0);
                pageObject.setData(null);
            }
        } catch (Exception e) {
            log.info("查询出错", e);
        }
        BoResultFormat.resultFormat(orderList, ModelConst.T_GOODSES);
        BOList bOList = new BOList();
        bOList.setData(orderList);
        bOList.setTotal(count);
        bOList.setSchemaCode(ModelConst.T_GOODSES);
        return com.alibaba.cola.dto.SingleResponse.of(bOList);
    }

    @Path("scoreStatistics")
    @POST
    @Operation(summary = "供应商评分-列表",tags = CUSTOM_SERVICE)
    public com.alibaba.cola.dto.SingleResponse<BOList> scoreStatistics(@Parameter ScoreStatisticsDto scoreStatisticsDto){
        Assert.isTrue(Objects.nonNull(scoreStatisticsDto),"参数不能为空");
        Assert.isTrue(StringUtils.isNotEmpty(scoreStatisticsDto.getScoreDate()),"评分时间不能为空");
        scoreStatisticsDto.setScoreDate(scoreStatisticsDto.getScoreDate().concat("-01"));
        ComplexCondition condition = new ComplexCondition();
        condition.setNature(Nature.AND);
        condition.getConditions().add(new SimpleCondition("scoreDate", Operator.EQ,scoreStatisticsDto.getScoreDate()));
        return BoServiceUtils.findListByConditionByPage("vendorScore",condition,scoreStatisticsDto.getPageIndex()-1,scoreStatisticsDto.getPageSize());
    }

    @Path("scoreStatisticsExport")
    @POST
    @Operation(summary = "供应商评分-列表导出",tags = CUSTOM_SERVICE)
    public com.alibaba.cola.dto.SingleResponse scoreStatisticsExport(@Parameter ScoreStatisticsExportDto scoreStatisticsDto){
        Assert.isTrue(Objects.nonNull(scoreStatisticsDto),"参数不能为空");
        Assert.isTrue(StringUtils.isNotEmpty(scoreStatisticsDto.getScoreDate()),"评分时间不能为空");
        scoreStatisticsDto.setScoreDate(scoreStatisticsDto.getScoreDate().concat("-01"));
        ComplexCondition condition = new ComplexCondition();
        condition.setNature(Nature.AND);
        condition.getConditions().add(new SimpleCondition("scoreDate", Operator.EQ,scoreStatisticsDto.getScoreDate()));
        com.alibaba.cola.dto.SingleResponse<BOList> response = BoServiceUtils.findListByCondition("vendorScore", condition);
        if(!response.isSuccess()){
            throw new BizException("查询失败，请稍后重试");
        }
        List<Map<String, Object>> data = response.getData().getData();
        ReportRecord record = ReportRecord.builder()
                .code("work-bench-vendor-score-report")
                .type(Optional.ofNullable(FileExportEnum.get(scoreStatisticsDto.getExportFileType())).orElseThrow(() -> new BizException("文件类型不支持")).getCode())
                .data(data.stream().map(v -> {
                    Map<String, Object> map = Maps.newHashMap();
                    map.put("vendorOrganizationName",v.get("vendorName"));
                    map.put("vendorOrganizationId",v.get("vendorNo"));
                    map.put("platform",v.get("vendorType"));
                    map.put("quotationFillScore",PmUtil.numberFormat((BigDecimal) v.get("reportSatisfyScore")).toPlainString());
                    map.put("quotationHourlyScore",PmUtil.numberFormat((BigDecimal) v.get("reportTimeScore")).toPlainString());
                    map.put("quotationBiddingScore",PmUtil.numberFormat((BigDecimal)v.get("reportWinScore")).toPlainString());
                    map.put("orderTimely",PmUtil.numberFormat((BigDecimal)v.get("acceptTimeScore")).toPlainString());
                    map.put("goodsTimely",PmUtil.numberFormat((BigDecimal)v.get("sendGoodTimeScore")).toPlainString());
                    map.put("totalResult",v.get("evaluateResult"));
                    map.put("statisticsTime",((String)v.get("scoreDate")).concat(" 00:00:00"));
                    return map;
                }).collect(Collectors.toList()))
                .build();
        Map singleResponse = RestTemplateUtil.rest(Objects.requireNonNull(PmUtil.getUrl(systemManagement)).concat(EXPORT_REPORT_URL), record, HttpMethod.POST);
        SingleResponse exportResponse = BoUtils.Map2Bo(singleResponse, SingleResponse.class);
        Assert.isTrue(exportResponse.isSuccess(),exportResponse.getErrMessage());
        return  com.alibaba.cola.dto.SingleResponse.of(singleResponse.get("data"));
    }

    @Path("scoreStatisticsJob")
    @POST
    @Operation(summary = "供应商评分统计任务",tags = CUSTOM_SERVICE)
    public SingleResponse scoreStatisticsJob(){
        log.info("==================供应商评分统计任务 开始执行==============");
        String startDateStr = PmUtil.getStartDateStr(Calendar.MONTH, -1);
        String endDateStr = PmUtil.getEndDateStr(Calendar.DATE, -1);
        String sql = "SELECT " +
                "vendor_organization_name," +
                "vendor_organization_id," +
                "platform," +
                "quotationfillscore," +
                "quotationhourlyscore," +
                "quotationbiddingscore," +
                "COALESCE ( ordertimely, 0 ) ordertimely," +
                "COALESCE ( goodstimely, 0 ) goodstimely," +
                "CASE " +
                "WHEN totalscore >= 70 " +
                "AND totalscore <= 110 THEN 'A类：核心供应商' " +
                "WHEN totalscore >= 60 " +
                "AND totalscore < 70 THEN 'B类：优质供应商'" +
                "WHEN totalscore >= 50 " +
                "AND totalscore < 60 THEN" +
                "'C类：普通供应商' " +
                "WHEN totalscore < 50 THEN" +
                "'D类：合格供应商' " +
                "END AS totalscore " +
                "FROM" +
                "(" +
                "SELECT " +
                "vendor_organization_name," +
                "vendor_organization_id," +
                "platform," +
                "quotationfillscore," +
                "quotationhourlyscore," +
                "quotationbiddingscore," +
                "ordertimely," +
                "goodstimely,(" +
                "quotationfillscore + quotationhourlyscore + quotationbiddingscore + COALESCE ( ordertimely, 0 ) + COALESCE ( goodstimely, 0 )) AS totalscore " +
                "FROM (" +
                "SELECT " +
                "quotation.vendor_organization_id," +
                "quotation.vendor_organization_name," +
                "quotation.platform," +
                "CASE WHEN quotation.quotationrate >= 0.75 " +
                "AND quotation.quotationrate <= 1.0 THEN 10 WHEN quotation.quotationrate >= 0.65 " +
                "AND quotation.quotationrate < 0.75 THEN 8 WHEN quotation.quotationrate >= 0.55 " +
                "AND quotation.quotationrate < 0.65 THEN 6 WHEN quotation.quotationrate >= 0.45 " +
                "AND quotation.quotationrate < 0.55 THEN 4 WHEN quotation.quotationrate >= 0.45 " +
                "AND quotation.quotationrate < 0.30 THEN 2 ELSE 0 END quotationfillscore, CASE WHEN quotation.quotationtime >= 0.0 " +
                "AND quotation.quotationtime <= 60 * 60 * 12 THEN 20 WHEN quotation.quotationtime > 60 * 60 * 12 " +
                "AND quotation.quotationtime <= 60 * 60 * 24 THEN 15 WHEN quotation.quotationtime > 60 * 60 * 24 " +
                "AND quotation.quotationtime <= 60 * 60 * 36 THEN 10 WHEN quotation.quotationtime > 60 * 60 * 36 " +
                "AND quotation.quotationtime <= 60 * 60 * 48 THEN 5 ELSE 0 END quotationhourlyscore, CASE WHEN quotation.rate >= 0.30 " +
                "AND quotation.rate <= 1.00 THEN 30 WHEN quotation.rate >= 0.25 " +
                "AND quotation.rate < 0.30 THEN 20 WHEN quotation.rate >= 0.20 " +
                "AND quotation.rate < 0.25 THEN 15 WHEN quotation.rate >= 0.15 " +
                "AND quotation.rate < 0.20 THEN 10 WHEN quotation.rate >= 0.10 " +
                "AND quotation.rate < 0.15 THEN 5 ELSE 0 " +
                "END quotationbiddingscore " +
                "FROM" +
                "(" +
                "SELECT " +
                "t.vendor_organization_id," +
                "t.vendor_organization_name," +
                "t.platform," +
                "CAST(" +
                "t.quote_count / t.partake_count AS DECIMAL ( 18, 2 )) AS quotationrate," +
                "EXTRACT(" +
                "SECOND " +
                "FROM" +
                "( t.quotationtime )) quotationtime," +
                "CAST(" +
                "t.rate AS DECIMAL ( 18, 2 )) rate " +
                "FROM" +
                "(" +
                "SELECT " +
                "q.vendor_organization_name," +
                "q.vendor_organization_id," +
                "CASE " +
                "WHEN o.platform IS TRUE THEN" +
                "'平台供应商' ELSE '原有供应商' " +
                "END AS platform," +
                "sum( CASE WHEN q.STATUS IN ( 3, 4, 5, 6 ) THEN 1.0 ELSE 0.0 END ) AS quote_count," +
                "sum(" +
                "CASE WHEN q.STATUS IN ( 0, 1, 2, 3, 4, 5, 6, 7 ) THEN " +
                "1.0 ELSE 0.0 " +
                "END " +
                ") AS partake_count," +
                "avg( q.createdTime - i.createdTime ) AS quotationtime," +
                "sum( CASE WHEN q.picketage IS TRUE AND q.del IS FALSE THEN 1.0 ELSE 0.0 END ) / sum( CASE WHEN q.del IS FALSE THEN 1.0 ELSE 0.0 END ) AS rate " +
                "FROM " +
                "`sourcingcenter`.i_sourcingcenter_t_quotation_goods q " +
                "LEFT JOIN `sourcingcenter`.i_sourcingcenter_t_inquiry_goods i ON i.id = q.inquiry_goods_id " +
                "LEFT JOIN `systemmanagement`.i_systemmanagement_t_organization o ON o.id = q.vendor_organization_id " +
                "WHERE " +
                "1 = 1 " +
                "AND i.createdTime >= :startDate " +
                "AND i.createdTime <= :endDate AND i.partake_count > 0 " +
                "AND i.del IS FALSE " +
                "AND o.del IS FALSE " +
                "AND q.del IS FALSE " +
                "GROUP BY " +
                "q.vendor_organization_name," +
                "q.vendor_organization_id," +
                "CASE WHEN o.platform IS TRUE THEN" +
                "'平台供应商' ELSE '原有供应商' " +
                "END " +
                ") AS t" +
                ") AS quotation " +
                ") AS quotationtable " +
                "LEFT JOIN (" +
                "SELECT " +
                "ordergoods.organization_id," +
                "CASE WHEN ordergoods.ordertimely >= 0.0 " +
                "AND ordergoods.ordertimely <= 60 * 60 * 8 THEN 20 WHEN ordergoods.ordertimely > 60 * 60 * 8 " +
                "AND ordergoods.ordertimely <= 60 * 60 * 36 THEN 15 WHEN ordergoods.ordertimely > 60 * 60 * 36 " +
                "AND ordergoods.ordertimely <= 60 * 60 * 48 THEN 10 WHEN ordergoods.ordertimely > 60 * 60 * 48 " +
                "AND ordergoods.ordertimely <= 60 * 60 * 60 THEN 5 ELSE 0 END ordertimely, CASE WHEN ordergoods.goodstimely >= 0.0 " +
                "AND ordergoods.goodstimely <= 60 * 60 * 8 THEN 30 WHEN ordergoods.goodstimely > 60 * 60 * 8 " +
                "AND ordergoods.goodstimely <= 60 * 60 * 24 THEN 25 WHEN ordergoods.goodstimely > 60 * 60 * 24 " +
                "AND ordergoods.goodstimely <= 60 * 60 * 48 THEN 20 WHEN ordergoods.goodstimely > 60 * 60 * 48 " +
                "AND ordergoods.goodstimely <= 60 * 60 * 60 THEN 15 WHEN ordergoods.goodstimely > 60 * 60 * 60 " +
                "AND ordergoods.goodstimely <= 60 * 60 * 72 THEN 10 WHEN ordergoods.goodstimely > 60 * 60 * 72 " +
                "AND ordergoods.goodstimely <= 60 * 60 * 84 THEN 5 ELSE 0 " +
                "END goodstimely " +
                "FROM(" +
                "SELECT " +
                "orders_table.organization_id," +
                "EXTRACT(" +
                "SECOND " +
                "FROM" +
                "( avg(orders_table.times ))) ordertimely," +
                "EXTRACT(" +
                "SECOND " +
                "FROM" +
                "( avg(orders_table.deliverytime) )) goodstimely " +
                "FROM" +
                "(" +
                "SELECT " +
                "T.organization_id," +
                "( T.confirm_order_time - T.createdTime ) AS times," +
                "( transport.createdTime - T.createdTime ) AS deliverytime " +
                "FROM " +
                "ordercenter.i_ordercenter_t_order_vendor T " +
                "LEFT JOIN ordercenter.i_ordercenter_t_order_vendor_goods ordergoods ON T.ID = ordergoods.order_vendor_id " +
                "LEFT JOIN ordercenter.i_ordercenter_t_order_trace transport ON ordergoods.ID = transport.order_vendor_goods_id " +
                "WHERE " +
                "T.createdTime >= :startDate " +
                "AND T.createdTime <= :endDate " +
                "AND T.del IS FALSE " +
                "AND ordergoods.del IS FALSE " +
                "AND transport.del IS FALSE " +
                ") AS orders_table " +
                "GROUP BY " +
                "orders_table.organization_id" +
                ") AS ordergoods " +
                ") AS goodstable ON quotationtable.vendor_organization_id = goodstable.organization_id " +
                ") AS a " +
                "ORDER BY " +
                "a.totalscore DESC";
        HashMap<String, Object> map = Maps.newHashMap();
        map.put("startDate",startDateStr);
        map.put("endDate",endDateStr);
        SqlParameterSource namedParameters = new MapSqlParameterSource(map);
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql, namedParameters);
        log.info("==================供应商评分统计任务 执行结束，记录数：{}==============",list.size());
        if(!CollectionUtils.isEmpty(list)){
            String dateStr = PmUtil.getDateStr(Calendar.MONDAY, -1, PmUtil.yyyyMMdd);
            list.forEach(f->f.put("scoreDate",dateStr));
            BoServiceUtils.createBo("vendorScore",list);
        }
        return SingleResponse.of("SUCCESS");


    }


    @Path("vendorStastics")
    @POST
    @Operation(summary = "供应商数据统计",tags = CUSTOM_SERVICE)
    public com.alibaba.cola.dto.SingleResponse<BOList> vendorStastics(@Parameter VendorStatsticsDto vendor){

        PageObject<VendorData> pageObject = new PageObject<VendorData>();
        try{
            Integer pageCurrent = vendor.getPageCurrent() == null ?  1:vendor.getPageCurrent();
            Integer pageSize = vendor.getPageSize() == null ? 10 :vendor.getPageSize();

            // 设置当前页
            vendor.setPageCurrent(pageCurrent);
            // 设置每页显示的条数
            pageObject.setPageSize(pageSize);
            // 设置总记录数

            int count = VendorStasticsJdbcUtil.queryAllVendorCount(vendor);
            log.info("总条数:{}"+count);
            pageObject.setRowCount(count);
            pageObject.setPageCount(0);
            if (count != 0 ){
                // 设置总页数
                int pageNum = count % pageSize == 0 ? count / pageSize : (count / pageSize) + 1;
                pageObject.setPageCount(pageNum);
                // 设置每页显示数据集合
                // 开始的记录数
                int start = (pageCurrent - 1) * pageSize;
                System.out.println(start+"-"+pageSize);
                List<Map<String, Object>> vendors = VendorStasticsJdbcUtil.queryAllVendor(vendor, start, pageSize);
                List<VendorData> list = new ArrayList<VendorData>();
                //查询所有的供应商信息
                convertMemberInfo(list, vendors);

                //查询所有供应商的负责人
                List<VendorPlateUser> vendorPlateUsers = VendorStasticsJdbcUtil.queryAllPlateUserOfVendor();
                convertVendorMember(list, vendorPlateUsers);


                //商品信息汇总
                List<VendorGood> vendorGoods = VendorStasticsJdbcUtil.queryGoodCountGroupByVendor(vendor);
                convertVendorGood(list,vendorGoods) ;




                //查询供应商报价信息
                List<VendorQuotationGoods> quotationGoods = VendorStasticsJdbcUtil.queryVendortQuotationGoods(vendor);
                convertVendorQuotation(list,quotationGoods);
                List<VendorQuotationGoodThirtySix> thirtySixQuotationGoods = VendorStasticsJdbcUtil.queryVendortQuotationGoodsThirtySix(vendor);
                convertVendorQuotationThirtySix(list,thirtySixQuotationGoods);

                //供应商订单
                List<VendorOrderStatistics> vendorGoodDtos = VendorStasticsJdbcUtil.queryVendorOrderStatsticsList(vendor);
                convertVendorOrder(list,vendorGoodDtos);
                pageObject.setData(list);
                List<Map<String, Object>> maps = convertObjOfListToMap(list);
                BoResultFormat.resultFormat(maps, "vendorStastics");
                BOList bOList = new BOList();
                bOList.setData(maps);
                bOList.setTotal(count);
                bOList.setSchemaCode("vendorStastics");
                return com.alibaba.cola.dto.SingleResponse.of(bOList);
            }else{
                pageObject.setPageCount(0);
                pageObject.setData(null);
            }
        }catch(Exception e){
            log.info("查询出错",e);
        }
        return com.alibaba.cola.dto.SingleResponse.error("1","查询出错");

    }

    public List<Map<String,Object>> convertObjOfListToMap(List<VendorData> list){
        List<Map<String,Object>> maps = new ArrayList<>();
        if (!CollectionUtils.isEmpty(list)){
            list.forEach(item->{
                Map<String,Object> map = new HashMap<>();
                maps.add(BeanUtil.beanToMap(item));
            });
        }
        return maps;
    }

    private void convertVendorOrder(List<VendorData> list, List<VendorOrderStatistics> vendorGoodDtos) {
        for(VendorOrderStatistics good : vendorGoodDtos){
            if (StringUtils.isNotBlank(good.getVendor_id())) {
                String vendorId = good.getVendor_id();
                SelectorFormat vendorIdFormat = Utils.toSelectorFormat(vendorId);
                String vendIdforUser = vendorIdFormat.getId();
                list.forEach(item->{
                    String id = item.getId();
                    if (id.equals(vendIdforUser)){
                        item.setZdcs(good.getZdcs());
                        item.setZdje(good.getZdje());
                        item.setWjds(good.getWjds());
                    }
                });
            }

        }

    }


    private void convertVendorQuotation(List<VendorData> list, List<VendorQuotationGoods> quotationGoods) {
        for(VendorQuotationGoods good : quotationGoods){
            String vendorId = good.getVendor_id();
            if (StringUtils.isNotBlank(vendorId)){
                SelectorFormat vendorIdFormat = Utils.toSelectorFormat(vendorId);
                log.info(vendorId);
                String vendIdforUser = vendorIdFormat.getId();
                list.forEach(item->{
                    String id = item.getId();
                    if (StringUtils.equals(id,vendIdforUser)){
                        item.setCycs(good.getCycs());
                        item.setZbcs(good.getZbcs());
                        item.setBjcs(good.getBjcs());
                        item.setBjl(good.getBjl());
                        item.setZdl(good.getZdl());
                    }
                });
            }

        }

    }
    private void convertVendorQuotationThirtySix(List<VendorData> list, List<VendorQuotationGoodThirtySix> quotationGoods) {
        for(VendorQuotationGoodThirtySix good : quotationGoods){
            String vendorId = good.getVendor_id();
            if (StringUtils.isNotBlank(vendorId)){
                SelectorFormat vendorIdFormat = Utils.toSelectorFormat(vendorId);
                String vendIdforUser = vendorIdFormat.getId();
                list.forEach(item->{
                    String id = item.getId();
                    if (id.equals(vendIdforUser)){
                        item.setThirtySixBjl(good.getThirtySixBjl());
                    }
                });
            }

        }

    }

    private void convertVendorGood(List<VendorData> list, List<VendorGood> vendorGoods) {
        for(VendorGood good : vendorGoods){
            String vendorId = good.getVendor_id();
            SelectorFormat vendorIdFormat = Utils.toSelectorFormat(vendorId);
            String vendIdforUser = vendorIdFormat.getId();
            list.forEach(item->{
                String id = item.getId();
                if (id.equals(vendIdforUser)){
                    item.setGoodNum(good.getGoodNum());
                    item.setBrandNum(good.getBrandNum());
                }
            });
        }


    }

    private void convertMemberInfo(List<VendorData> list, List<Map<String, Object>> vendors) {
        if (vendors != null && vendors.size() > 0){
            vendors.forEach(item->{
                VendorData obj = new VendorData();
                obj.setId((String) item.get("id"));
                obj.setVendorNum((String) item.get("id"));
                obj.setVendorName((String) item.get("name"));
                list.add(obj);
            });
        }
    }

    private void convertVendorMember(List<VendorData> list, List<VendorPlateUser> vendorPlateUsers) {
        for(VendorPlateUser user : vendorPlateUsers){
            String vendorId = user.getVendor_id();
            if(StringUtils.isBlank(vendorId)){
                continue;
            }
            SelectorFormat vendorIdFormat = Utils.toSelectorFormat(vendorId);
            String vendIdforUser = vendorIdFormat.getId();
            list.forEach(item->{
                String id = item.getId();
                if (id.equals(vendIdforUser)){
                    if (StringUtils.isNotBlank(user.getMemberId())){
                        SelectorFormat userMemberSelector = Utils.toSelectorFormat(user.getMemberId());
                        item.setMemberId(userMemberSelector.getName());
                    }
                }
            });
        }
    }

    /**
     * 供应商详情
     *
     * @param dto
     * @return
     */
    @Path("vendorDetail")
    @POST
    @Operation(summary = "供应商详情", tags = CUSTOM_SERVICE, description = "id、pageIndex、pageSize必填")
    public SingleResponse vendorDetail(@Parameter OrderVendorDto dto) {
        String url = HttpClientUtil.getUrl(AppConst.ORDER_CENTER, ServiceUrlConst.VENDOR_DETAIL_URL);
        Map<String, Object> map = BeanUtil.beanToMap(dto);
        String execute = HttpClientUtil.execute(url, map);
        BOList boList = JSONObject.parseObject(execute, BOList.class);
        return  SingleResponse.of(boList.getData().get(0));
    }



}
